package collection.list;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Demo {
    public static void main(String[] args) {
        //List有序、可重复、有索引
        List<String> list = addList();
        //删除元素
        list.remove("Python");
        System.out.println(list);
        //判断集合是否为空
        System.out.println(list.isEmpty());
        //清空集合元素
        //list.clear();
        //把集合转换成数组
        Object[] array = list.toArray();
        System.out.println(Arrays.toString(array));
        //拓展
        String[] arr2 = list.toArray(String[]::new);
        System.out.println(Arrays.toString(arr2));

        for (int i = 0; i < list.size(); i++) {
            list.remove("C++");
            System.out.println(list.get(i));
        }


    }

    public static List<String> addList() {
        List<String> list = new ArrayList<>();
        list.add("Java");
        list.add("Python");
        list.add("C++");
        list.add("JavaScript");
        list.add("JavaScript");
        System.out.println(list);
        return list;
    }
}
